package com.bml.architect.rocketmq.web;

import com.bml.architect.rocketmq.producer.DefaultProducer;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/producer")
public class ProducerController {


    private final String TOPIC = "springBoot-Topic";

    @Resource
    private DefaultProducer defaultProducer;


    @RequestMapping("/v1")
    public String send(@RequestParam(name = "msg") String msg) {
        defaultProducer.sendMsg(TOPIC, msg);
        System.out.println("消息发送成功");
        return "normal message send success!";
    }

    @RequestMapping("/v2")
    public String sendTx(@RequestParam(name = "msg") String msg) {
        defaultProducer.sendTxMsg(TOPIC, msg);
        System.out.println("事务消息发送成功");
        return "tranactions message send success!";
    }

    @RequestMapping("/v3")
    public String sendTxExt(@RequestParam(name = "msg") String msg) {
        defaultProducer.sendTxExtMsg(TOPIC, msg);
        System.out.println("扩展事务消息发送成功");
        return "extTranactions message send success!";
    }

}
